<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>localStorage</title>
</head>
<body>
    <h2>localStorage</h2>
    <button onclick="save()">点我保存数据</button><hr>
    <button onclick="getData()">点我获取数据</button><hr>
    <button onclick="deleteData()">点我删除数据</button><hr>
    <button onclick="clearData()">点我清空数据</button><hr>

    <script>
        let p = {name:'张三',age:18}
        console.log(p.toString())

        function save(){
            localStorage.setItem('msg','123')
            localStorage.setItem('123',345)
            localStorage.setItem('p',p)
        }

        function getData(){
            alert(localStorage.getItem('123'))
        }

        function deleteData(){
            localStorage.removeItem('p')
        }

        function clearData(){
            localStorage.clear()
        }
    </script>
</body>
</html>